/*
	
	@ by Demontf 

	@ for ekola 

	@ Home Module Service

 */

var homeApp = angular.module("homeApp",["ngRoute","appDirective","appWxShareDirective"]);

homeApp.service("commonService",function($http){
	// post 请求
	this.httpReq = function(url,formDataStr,callback){
		$http({
			url: url,
			method: "post",
		   	data: formDataStr,
		   	headers:{
		   		"Content-Type":"application/x-www-form-urlencoded",
		   	},
		}).success(function(response){
			if( "function" == typeof callback ){
				callback(response);
			}
		}).error(function(){
			console.log("http error...")
		});
	}

	this.checkTages = function(tagName){
		if("undefined" == typeof tagName) return false;

		var reg = /^[\u4E00-\u9FA5\uf900-\ufa2d\w\!\！\.\~\ ]{2,10}$/;
		if(!reg.test(tagName)){
			return false;
		}else{
			return true;
		}
	}

	this.totalPageList = function(curPage,totalPage){
		var list = [];

		if(totalPage <= 10){
			var pageStart = 1;
			var pageEnd = totalPage;
		}else if(totalPage - curPage > 5 && curPage >= 10){
			var pageStart = curPage - 4;
			var pageEnd = curPage + 5;
		}else if(totalPage - curPage <= 5 && curPage >= 10){
			var pageStart = totalPage - 10;
			var pageEnd = totalPage;
		}else if( curPage < 10 && totalPage > 10 ){
			var pageStart = 1;
			var pageEnd = 10;
		}
		for(var i = pageStart ; i <= pageEnd; i++){
			list.push(i);
		}

		return list;
	}

})